/*
 * Created by hql on 2024-08-14 16:55:44
 */

using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;

namespace IMMotors
{
    public class CoroutineHelper : MonoSingleton<CoroutineHelper>
    {
        public IEnumerator GetTexture(string url,UnityAction<Texture> callback)
        {
            using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
            {
                yield return uwr.SendWebRequest();
                if (uwr.result != UnityWebRequest.Result.Success)Debug.Log(uwr.error);
                else
                {
                    var texture = DownloadHandlerTexture.GetContent(uwr);
                    texture.wrapMode = TextureWrapMode.Clamp;
                    callback?.Invoke(texture);
                }
            }
        }
    }
}
